home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Otherware
/
Otherware_1_SB_Development.iso
/
mac
/
hypercar
/
xfcn
/
spttool.cpt
/
Support Tools eXternals 1.2.5
/
card_38837.txt
< prev
next >
Wrap
Text File
|
1990-11-13
|
7KB
|
243 lines
-- card: 38837 from stack: in.5
-- bmap block id: 43907
-- flags: 0000
-- background id: 3858
-- name: NumToHex
----- HyperTalk script -----
on hideObjects
hide cd fld "label"
hide cd fld "label 2"
hide cd fld "decimal"
hide cd fld "hex"
hide cd btn "convert"
end hideObjects
on showObjects
show cd fld "label"
show cd fld "label 2"
show cd fld "decimal"
show cd fld "hex"
show cd btn "convert"
end showObjects
-- part 2 (field)
-- low flags: 00
-- high flags: 0002
-- rect: left=103 top=159 right=179 bottom=240
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 12
-- style flags: 256
-- line height: 16
-- part name: Decimal
----- HyperTalk script -----
on ReturnInField
send mouseUp to cd btn "convert"
end ReturnInField
on EnterInField
send mouseUp to cd btn "convert"
end EnterInField
-- part 3 (field)
-- low flags: 01
-- high flags: 0000
-- rect: left=45 top=161 right=178 bottom=96
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 65535
-- font id: 3
-- text size: 10
-- style flags: 0
-- line height: 13
-- part name: label
-- part 4 (field)
-- low flags: 01
-- high flags: 0000
-- rect: left=45 top=237 right=254 bottom=96
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 65535
-- font id: 3
-- text size: 10
-- style flags: 0
-- line height: 13
-- part name: label 2
-- part 5 (field)
-- low flags: 00
-- high flags: 0002
-- rect: left=103 top=234 right=254 bottom=240
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 12
-- style flags: 256
-- line height: 16
-- part name: Hex
-- part 6 (button)
-- low flags: 00
-- high flags: A002
-- rect: left=82 top=191 right=225 bottom=175
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 8192
-- line height: 16
-- part name: Convert
----- HyperTalk script -----
on mouseUp
put NumToHex(cd fld "decimal") into cd fld "hex"
end mouseUp
-- part contents for background part 38
----- text -----
33/50
-- part contents for card part 3
----- text -----
Decimal
-- part contents for card part 4
----- text -----
Hex
-- part contents for card part 2
----- text -----
25567
-- part contents for card part 5
----- text -----
63DF
-- part contents for background part 20
----- text -----
This XFCN returns the hexidecimal representation (base 16, 0-F) of a decimal number.
Calling syntax : NumToHex(decimalNumber)
DECIMALNUMBER: the number to convert.
-- part contents for background part 42
----- text -----
{ NumToHex(theNumber) }
{ Change a number to a string representing it's hexadecimal value. }
{}
{ brought to you by: Anup Murarka Eric Carlson }
{ ALINK: SKEPTIC ALINK: cyNic }
{ CIS: 76004,3356 }
{}
{ We are part of the Support Tools Development Group, }
{ Apple Computer, Inc. }
{}
{ please DO NOT contack Mac DTS for support of this code! }
{}
{ please DO contact the authors for support of this code! }
{}
{ Send comments, bug reports, requests to any of the above }
{ E-mail addresses or to:}
{}
{ (one of us) }
{ Apple Computer, Inc. }
{ 900 E. Hamilton, Ave. }
{ Campbell, CA 95008 }
{ M/S 72-L }
{}
{ Copyright: © 1989, 1990 by Apple Computer, Inc., all rights reserved. }
{}
{ written by Eric Carlson }
{ AppleLink: cyNic }
{ modification history }
{ Date Initials Comments }
{ ---- ------ --------------------------------------------------}
{ 11/20/89 ec first written }
{ 6/6/90 ec commented, cleaned code }
{}
unit NumToHex;
interface
uses
HyperXCMD;
procedure main (paramPtr: XCmdPtr);
implementation
function askedForHelp (paramPtr: XCmdPtr;
syntaxMsg: Str255;
copyRightMsg: Str255): boolean;
{}
{ check to see if the user sent a '?' or a '!' as }
{ the only parameter. if so we will respond with }
{ the calling syntax or the copyright/version info }
{ for this external }
{}
var
firstStr: str255;
begin
askedForHelp := false;
if paramPtr^.paramCount = 1 then
begin
ZeroToPas(paramPtr, paramPtr^.params[1]^, firstStr);
{ what is the first param? }
if firstStr = '?' then
begin
paramPtr^.returnValue := PasToZero(paramPtr, syntaxMsg);
askedForHelp := true
end { asked for help }
else if firstStr = '!' then
begin
paramPtr^.returnValue := PasToZero(paramPtr, copyRightMsg);
askedForHelp := true
end; { asked for copyright info }
end; { one parameter passed }
end; { function }
procedure NumberToHex (paramPtr: XCMDPtr);
const
LoNibble = $000F; { low 4 bits }
var
copyRtStr, syntaxStr, tempStr: str255;
theNumber, hexCount: LONGINT;
HexDigits: string[16];
begin
syntaxStr := 'NumToHex(theNumber)';
copyRtStr := '© 1989,1990 Apple Computer, Inc. v.1.0, by Eric Carlson.';
if askedForHelp(paramPtr, syntaxStr, copyRtStr) then { asking for help? }
exit(NumberToHex);
zeroToPas(paramPtr, paramPtr^.params[1]^, tempStr); { the value to convert }
theNumber := StrToNum(paramPtr, tempStr);
HexDigits := '0123456789ABCDEF'; { All of the valid Hex digits}
tempStr[4] := HexDigits[BitAnd(theNumber, loNibble) + 1]; {Add 1 so that we skip over the string length byte}
theNumber := BSR(theNumber, 4); { shift past the byte we just examined }
tempStr[3] := HexDigits[BitAnd(theNumber, loNibble) + 1]; { etc… }
theNumber := BSR(theNumber, 4);
tempStr[2] := HexDigits[BitAnd(theNumber, loNibble) + 1];
theNumber := BSR(theNumber, 4);
tempStr[1] := HexDigits[BitAnd(theNumber, loNibble) + 1];
paramPtr^.returnValue := PasToZero(paramPtr, tempStr);
end;
procedure main (paramPtr: XCmdPtr);
begin
NumberToHex(paramPtr);
end;
end.